package swing;

import javax.swing.*;

import java.awt.*;
import java.util.List;
import java.util.Observable;
import java.util.Observer;

public abstract class StackPanel<TList, TItem> extends JPanel implements Observer {
    /**
	 * 
	 */
	private static final long serialVersionUID = -3737840738640602895L;


	protected abstract Component createItemPanel(TItem item);

    @SuppressWarnings("unchecked")
	@Override
    public final void update(Observable o, Object arg) {
        removeAll();
        List<TItem> list = parse((TList) arg);
        for(TItem item : list)
            add(createItemPanel(item));
    }


    protected abstract List<TItem> parse(TList arg);
}
